<template>
  <div id="nursingListDetails" class="mainContent">
    <div class="timeBox"> <vue-datepicker-local v-model="emptyTime" clearable /></div>
    <div class="list-link cleatfix" v-if="nursingData">
      <div v-for="(item,index) in nursingData" @click="change($event)" :data-name="item.MemoryAddress" class="nursingBox">
        <img src="./../../../../static/images/thd-blue.png" width="80" alt="Alternate Text" />
        <div>{{item.Abbreviation | filterData}}</div>
      </div>
    </div>

    <noSearch v-if="!isShow && nursingData.length == 0"></noSearch>
    <loading v-if="isShow && nursingData.length == 0"></loading>
  </div>

 
</template>
<script>
  import axios from 'axios';
  import loading from '@/components/loading/loading'
  import noSearch from '@/components/search/noSearch' //导入没有搜索结果组件
  import VueDatepickerLocal from '@/components/datepicker/VueDatepickerLocal'
  import { apiNursingSheet } from '@/api/api'
  import Bus from "@/components/common/bus"; //引入公共媒介JS BUS
export default {
    data() {
      return {
        nursingData: [],
        src: '',
        ind: 0,
        isShow: true,
        emptyTime: '',
        timeData: [],
        dataTime:"0000-00-00",
      }
    },
    watch: {
      dataTime: {
        handler(curVal, oldVal) {
          if (this.dataTime == '') {
            this.nursingData = [];
            this.timeData = [];
            this.dataTime = "0000-00-00";
            this.isShow = true;
            this.getNursingSheet();
          } else if (this.dataTime == "0000-00-00") {
            this.nursingData = [];
            this.timeData = [];
            this.isShow = true;
            this.getNursingSheet();
          } else {
            this.nursingData = [];
            this.timeData = [];
            this.isShow = true;
            this.getNursingSheet();
          }
        }
      }
    },
    created() {
      this.src = axios.defaults.baseURL.replace("api", "");
      //console.log(this.src)
    },
    mounted() {
      this.getNursingSheet();
      Bus.$on("timePicker", e => {
        this.dataTime = e.trim();
      });
    },

    methods: {
      changeBgc(index) {
        this.ind = index;
      },
      getNursingSheet() {
        apiNursingSheet({
          patientIdIn: this.$store.getters.ID,
          dateTime: this.dataTime
        })
          .then(res => {
            this.nursingData = [];
            this.timeData = [];
            if (res.Status == -1)
            {
              this.isShow = false;
            }
            if (res.Status == 1) {
              this.isShow = true;
              for (let item of JSON.parse(res.Data)) {
                if ($.inArray(this.filterDate(item.Abbreviation), this.timeData) == -1) {
                  this.timeData.push(this.filterDate(item.Abbreviation));
                  this.nursingData.push(item);
                }
              }
            }
          })
      },
      change(e) {
        this.src = axios.defaults.baseURL.replace("api", "") + e.currentTarget.getAttribute("data-name").replace("AppServerWeb", "");
        this.$router.push({
          path: '/nursingPdf',
          query: {http:this.src}
        })
      },
      filterDate(str) {
        if (!str) {
          return ''
        } else {
          return str.substring(str.indexOf('圳') + 1, 28);
        }
      },
    },
    filters: {
      filterData(str) {
        if (!str) {
          return str
        } else {
            str = str.replace('重症北大深圳', '').substring(9, 22);
          if (str.indexOf('01_') != -1) {
            let type = str.replace('01_', '_A面').substring(0, 3);
            let date = str.substring(3, 20);
            return date.concat(type); 
          } else if (str.indexOf('02_') != -1) {
            let type = str.replace('02_', '_B面').substring(0, 3);
            let date = str.substring(3, 20);
            return date.concat(type); 
          } else if (str.indexOf('03_') != -1) {
            let type = str.replace('03_', '_A面').substring(0, 3);
            let date = str.substring(3, 20);
            return date.concat(type);
          } else if (str.indexOf('04_') != -1) {
            let type = str.replace('04_', '_B面').substring(0, 3);
            let date = str.substring(3, 20);
            return date.concat(type);
          }
        
        }
      }
    },
   
    components: {
      loading,
      VueDatepickerLocal,
      noSearch
    }
}
</script>
<style scoped>
  #nursingListDetails{
    height: 100%;
    width: 100%;
    padding:15px;

  }
  .list-link{
    width:100%;
    height:calc(100vh - 200px);
    overflow-y:auto;
  }
  .nursingBox{
    float:left;
    width:140px;
    margin-left:15px;
    margin-bottom:45px;
    text-align:center;
  }
    .nursingBox > div {
      display:flex;
      margin-top:10px;
      justify-content:center;
      align-items:center;
    }
    .timeBox {
      padding-left: 46px;
      padding-bottom:20px;
    }


</style>
